package com.example.javaee.mapper;

import com.example.javaee.entity.Employee;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface EmployeeMapper {
    @Results(id = "employeeMap", value = {
            @Result(property = "员工工号", column = "员工工号"),
            @Result(property = "姓名", column = "姓名"),
            @Result(property = "性别", column = "性别"),
            @Result(property = "年龄", column = "年龄")
    })
    @Select("SELECT * FROM 员工信息表")
    List<Employee> findAll();

    @Select("SELECT * FROM 员工信息表 WHERE 姓名 LIKE CONCAT('%', #{keyword}, '%')")
    List<Employee> search(String keyword);

    @Insert("INSERT INTO 员工信息表(员工工号, 姓名, 性别, 年龄) " +
            "VALUES(#{员工工号}, #{姓名}, #{性别}, #{年龄})")
    int insert(Employee employee);

    @Update("UPDATE 员工信息表 SET 姓名=#{姓名}, 性别=#{性别}, " +
            "年龄=#{年龄} WHERE 员工工号=#{员工工号}")
    int update(Employee employee);

    @Delete("DELETE FROM 员工信息表 WHERE 员工工号=#{员工工号}")
    int delete(String 员工工号);
}
